package com.jackrain.nea.clould.dao;

import com.jackrain.nea.clould.model.ONSConsumerMQModel;
import com.jackrain.nea.util.Tools;
import com.jackrain.nea.web.query.QueryEngine;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.sql.Timestamp;

/**
 * 消费者
 */
@Slf4j
@Component
public class ONSConsumerMQDao {


    public int insert(ONSConsumerMQModel onsConsumerMQModel) throws Exception {

        if (onsConsumerMQModel.getId() <= 0) {
            onsConsumerMQModel.setId(Tools.getInt(com.jackrain.nea.core.db.Tools.getSequence("ons_consumermq"), 0));
        }

        String sql = "insert into ons_consumermq " +
                "(id,ad_client_id,ons_xtype,state," +
                "error,consumerip,pdesc,datacount," +
                "msgkey,ons_sendmonitorid,sendkey," +
                "ownerid,modifierid,creationdate,modifieddate,isactive)" +
                "values(?,?,?,?," +
                "?,?,?,?," +
                "?,?,?," +
                "?,?,?,?,?) ";

        Timestamp time = new Timestamp(System.currentTimeMillis());

        int ret = QueryEngine.getInstance().executeUpdate(sql, new Object[]{
                onsConsumerMQModel.getId(), onsConsumerMQModel.getAd_client_id(), onsConsumerMQModel.getOns_xtype(), onsConsumerMQModel.getState(),
                onsConsumerMQModel.getError(), onsConsumerMQModel.getConsumerip(), onsConsumerMQModel.getPdesc(), onsConsumerMQModel.getDatacount(),
                onsConsumerMQModel.getMsgkey(), onsConsumerMQModel.getOns_sendmonitorid(), onsConsumerMQModel.getSendkey(),
                893, 893, time, time, "Y"});


        return ret;

    }

    public int update(String state, String error, String pdesc, int datacount, long id) {

        String sql = "update ons_consumermq set state = ? ,error = ?,pdesc=? ,datacount =? where id = ?";

        int ret = QueryEngine.getInstance().executeUpdate(sql, new Object[]{state, error, pdesc,datacount, id});

        return ret;


    }


}
